package com.spring.controller;

import com.spring.pojo.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class BookController {

    @GetMapping("/books")
    public ModelAndView books(){
        List<Book> books=new ArrayList<>();
        Book b1=new Book();
        b1.setAuthor("罗贯中");
        b1.setName("三国演义");
        b1.setPrice(50);
        List<String> list=new ArrayList<>();
        list.add("yyc");
        list.add("fjj");
        b1.setBorrow(list);
        Book b2=new Book();
        b2.setAuthor("曹雪芹");
        b2.setName("红楼梦");
        b2.setPrice(40);
        List<String> list2=new ArrayList<>();
        list2.add("fyx");
        list2.add("wc");
        b2.setBorrow(list2);
        books.add(b1);
        books.add(b2);
        ModelAndView mv=new ModelAndView();
        mv.addObject("books",books);
        mv.setViewName("books");
        return mv;
    }
}
